import { onMounted, ref } from "vue";
export function useTable() {
  /**
   * 商品数据列表
   */
  const dataList = ref([]);
  /**
   * 商品表格列
   */
  const tableColumns: TableColumnList = [
    {
      label: "商品编号",
      prop: "fgoodcode",
      cellRenderer: ({ row }) => <el-input v-model={row.fgoodcode} />
    },
    {
      label: "商品名称",
      prop: "fgoodname",
      cellRenderer: ({ row }) => <el-input v-model={row.fgoodname} />
    },
    {
      label: "品牌",
      prop: "fbrand",
      cellRenderer: ({ row }) => <el-input v-model={row.fbrand} />
    },
    {
      label: "规格",
      prop: "fspec",
      cellRenderer: ({ row }) => <el-input v-model={row.fspec} />
    },
    {
      label: "单价",
      prop: "fprice",
      cellRenderer: ({ row }) => <el-input v-model={row.fprice} />
    },
    {
      label: "数量",
      prop: "fquantity",
      cellRenderer: ({ row }) => <el-input v-model={row.fquantity} />
    },
    {
      label: "总价",
      prop: "fbidprice",
      cellRenderer: ({ row }) => <el-input v-model={row.fbidprice} />
    },
    {
      label: "单位",
      prop: "funit",
      cellRenderer: ({ row }) => <el-input v-model={row.funit} />
    }
  ];

  /**
   * 添加一行商品数据
   */
  function onAdd() {
    dataList.value.push({
      id: dataList.value.length + 1,
      fgoodcode: "",
      fgoodname: "",
      fbrand: "",
      fspec: "",
      fprice: 0,
      fquantity: 0,
      fbidprice: 0,
      funit: ""
    });
  }
  return {
    dataList,
    tableColumns,
    onAdd
  };
}
